<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('auto_marking_records', function (Blueprint $table) {
            $table->id();
            $table->string('subjective_id', 100)->nullable()->comment('主观题ID');
            $table->string('subjective_item_id', 100)->nullable()->comment('主观题项目ID');
            $table->string('group_id', 100)->nullable()->comment('组ID');
            $table->integer('question_no')->nullable()->comment('题目编号');
            $table->string('secret_num')->nullable()->comment('密号');
            $table->string('image_url')->nullable()->comment('题目图片URL');
            $table->json('question_data')->nullable()->comment('完整题目数据JSON');
            $table->json('ocr_content_list')->nullable()->comment('OCR识别的作文内容列表');
            $table->text('ocr_full_text')->nullable()->comment('OCR识别的完整文本内容');
            $table->integer('word_count')->default(0)->comment('字数统计');
            $table->integer('line_count')->default(0)->comment('行数统计');
            $table->json('ai_score_results')->nullable()->comment('AI打分结果详情');
            $table->decimal('average_score', 5, 2)->nullable()->comment('AI平均分');
            $table->decimal('adjusted_score', 5, 2)->nullable()->comment('微调后最终分数');
            $table->decimal('submitted_score', 5, 2)->nullable()->comment('实际提交的分数');
            $table->json('submit_result')->nullable()->comment('提交结果JSON');
            $table->boolean('is_submitted')->default(false)->comment('是否已提交');
            $table->text('error_message')->nullable()->comment('错误信息');
            $table->timestamp('processed_at')->nullable()->comment('处理时间');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['subjective_id', 'subjective_item_id']);
            $table->index('processed_at');
            $table->index('is_submitted');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('auto_marking_records');
    }
};
